<?php

namespace App\Http\Requests;

use App\Models\CoinsApplication;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class CoinsApplicationUpdateRequest extends FormRequest
{
    use CommonRequest;

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            'name' => [
                'required',
                Rule::unique((new CoinsApplication())->getTable(), 'name')
            ],
            'description' => 'required',
        ];
        $rules = array_merge($rules, CoinsApplicationRequest::baseRules());

        return $rules;
    }

    public function messages()
    {
        $id = request()->input('id');

        $messages = [
            'name.required' => '应用名称必填',
            'name.unique' => '应用名称已存在',
            'description.required' => '描述不能为空',
        ];

        if (!empty($id)) {
            $messages = array_merge($messages, CoinsApplicationRequest::baseMessages());
        }

        return $messages;

    }
}
